﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace 易容酒店管理系统
{
    public partial class Reserve : Form
    {
        public Reserve()
        {
            InitializeComponent();
        }
        private Point mouse_offset;//获取窗体当前X，Y的坐标
        private void panel1_MouseDown(object sender, MouseEventArgs e)
        {
            mouse_offset = new Point(-e.X, -e.Y);//获取移动后的坐标
        }

        private void panel1_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)//判断窗体位置是否发生了移动
            {
                Point mousePos = Control.MousePosition;             //更改窗体当前的X，Y坐标
                mousePos.Offset(mouse_offset.X, mouse_offset.Y);
                Location = mousePos;
            }
        }

        private void butReserve_Click(object sender, EventArgs e)
        {
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            DateTime InTime = dateInTime.Value;
            DateTime OutTime = dateOutTime.Value;
            using (SqlConnection con = new SqlConnection(Link))
            {
                string Sql = "insert into Customer_Reserve values";
                Sql += "('" + txtName.Text + "','" + cobPapers.Text + "','" + txtID.Text + "','" + txtTelephone.Text + "','"+text.Text+"','" + InTime.ToString("yyyy-MM-dd") + "','";
                Sql += OutTime.ToString("yyyy-MM-dd") + "','" + comType.Text + "','" + comMeoth.Text + "','" + comReserve.Text + "')";
                using (SqlCommand cmd = new SqlCommand(Sql, con))
                {
                    con.Open();
                    int num = cmd.ExecuteNonQuery();
                    if (num>0)
                    {
                        MessageBox.Show("登记完成房间号为：" + Room());
                    }
                    con.Close();
                }
                string Sql2 = "update GuestInfo set Reserve='已预订' where RoomID='" + Room() + "'";
                using (SqlCommand cmd2 = new SqlCommand(Sql2, con))
                {
                    con.Open();
                    int num = cmd2.ExecuteNonQuery();
                    if (num > 0)
                    {
                        //
                    }
                }
            }
        }
        /// <summary>
        /// 分配客房
        /// </summary>
        /// <returns></returns>
        private string Room()
        {
            string ID = "";
            string Link = "Server=.;Database=Management_system;integrated security=SSPI;";
            using (SqlConnection con = new SqlConnection(Link))
            {
                string Sql = "select top 1 RoomID from GuestInfo where Type='" + comType.Text + "'and GusetInfo='无' and setting='已打扫' and Reserve='未预订';";
                using (SqlCommand cmd = new SqlCommand(Sql, con))
                {
                    con.Open();
                    ID = (string)cmd.ExecuteScalar();
                }
            }
            return ID;
        }

        private void picColse_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
